<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <base href="<%=basePath %>" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <link href="ui/css/layui.css" rel="stylesheet"/>
    <script type="text/javascript" src="ui/layui.js"></script>
    <script type="text/javascript" src="ui/jquery-1.11.1.min.js"></script>
</head>
<body>
<%--我来组成头部--%>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    ${wUsername}
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="logout.do">退出</a></li>
        </ul>
    </div>
</div>
<%--弹出表单--%>
<form class="layui-form" id="leaveNoteForm" style="display:none">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label" >留言</label>
        <div class="layui-input-block">
            <textarea id="uMessage" lay-verify="required" name="desc" placeholder="会什么赶紧说" class="layui-textarea"></textarea>
        </div>
    </div>
</form>


<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg4 box">

            <div class="layui-form-item">
                <label class="layui-form-label">按公司查询</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required  id="firmName" lay-verify="required" placeholder="请输入公司" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="searchBtnFirm"  lay-filter="formDemo">搜索</button>
                </div>
            </div>



        </div>
        <div class="layui-col-lg4 box">

            <div class="layui-form-item">
                <label class="layui-form-label">按职业查询</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required  id="jobName" lay-verify="required" placeholder="请输入职业" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="searchBtnJob" lay-submit lay-filter="formDemo">搜索</button>
                </div>
            </div>

        </div>
        <div class="layui-col-lg4 box">
            <div style="float: right;">
                <a class="layui-btn layui-btn-warm" href="worker/checkMyResume.do">查看简历</a>
                <a class="layui-btn layui-btn-normal" href="apply-list.jsp">查看已申请职位</a>
            </div>
        </div>
    </div>
    <table id="jobTable" lay-filter="test"></table>
    <script type="text/html" id="bar">
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="detail">查看</button>
        <button id="applyBtn" class="layui-btn layui-btn-sm" lay-event="apply">申请</button>
    </script>

</div>

<script>
    layui.use('form');
    //查看职业信息
    layui.use("table",function(){
        var table=layui.table;
        table.render({
            elem:"#jobTable",
            url:"findAllJobs2.do",
            // parseData:function(res){
            //     return {
            //         code:0,
            //         msg:'工作表',
            //         count:11,
            //         data:res
            //     };
            // },
            cols:[[
                {field:"jobName",title:"名称",width:150},
                {field:"firmName",title:"企业",width:150},
                {field:"jobRequire",title:"职位要求",width:200},
                {field:"treatment",title:"待遇",width:200},
                {field:"",title:"操作",width:200,toolbar:"#bar"}
            ]],
            page:true,
            limit:5,
            limits:[5,10,20]
        });
        table.on('tool(test)', function(obj){
            var data = obj.data;
            data=obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            }else if(obj.event === 'apply'){
                //点击申请按钮
                layui.use('layer',function() {
                    var layer = layui.layer;
                    var form = layui.form;
                    var $ = layui.jquery;

                    layer.open({
                        type: 1,
                        area: ['500px', '600px'],
                        title: '申请工作并留言',
                        content: $("#leaveNoteForm"),
                        shade: 0,
                        btn: ['提交', '重置'],
                        btn1: function(index, layero) {
                            var uMessage = $("#uMessage").val();
                            $.ajax({
                                url: 'worker/applyForJob.do',
                                type: 'post',
                                dataType: 'text',
                                data: {
                                    jobId: data.id,
                                    uMessage: uMessage
                                },

                                success: function(data) {
                                    if (data == 1) {
                                        layer.msg('申请成功');
                                        ///location.href = "login.html";
                                    } else {
                                        layer.msg('申请失败');
                                    }
                                }
                            })
                        },
                        btn2: function(index, layero) {
                            $("#leaveNoteForm")[0].reset();
                            return false;
                        },
                        cancel: function(layero, index) {
                            layer.closeAll();
                        }

                    });



                })
                // window.location.href="applyForJob.jsp?jobId="+data.id;

            }
        });
    });
    //通过公司名查找(ajax)

    $("#searchBtnFirm").click(function () {
        layui.use('table', function(){
            var table = layui.table;
            var firmName = $("#firmName").val();
            table.render({
                elem: "#jobTable",
                url: "searchByFirm.do?firmName=" + firmName,
                parseData: function (res) {
                    return {
                        code: 0,
                        msg: '工作表',
                        count: res.length,
                        data: res
                    };
                },
                cols: [[
                    {field: "jobName", title: "名称", width: 150},
                    {field: "firmName", title: "企业", width: 150},
                    {field: "jobRequire", title: "职位要求", width: 200},
                    {field: "treatment", title: "待遇", width: 200},
                    {field: "", title: "操作", width: 200, toolbar: "#bar"}
                ]]
            });
        })
    })
    $("#searchBtnJob").click(function () {
        layui.use('table', function(){
            var table = layui.table;
            var jobName = $("#jobName").val();
            table.render({
                elem: "#jobTable",
                url: "searchByJob.do?jobName=" + jobName,
                parseData: function (res) {
                    return {
                        code: 0,
                        msg: '工作表',
                        count: res.length,
                        data: res
                    };
                },
                cols: [[
                    {field: "jobName", title: "名称", width: 150},
                    {field: "firmName", title: "企业", width: 150},
                    {field: "jobRequire", title: "职位要求", width: 200},
                    {field: "treatment", title: "待遇", width: 200},
                    {field: "", title: "操作", width: 200, toolbar: "#bar"}
                ]]
            });
        })
    })


</script>
</body>
</html>